package com.cgs.query.service.jpa

import com.cgs.query.domain.Project2Define
import com.cgs.query.service.AliasDefineNameVersionVO
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query

interface Project2DefineRepository : JpaRepository<Project2Define, Int> {

    fun findByDefineIdAndAliasAndProjectName(defineId: String, alias: String, projectName: String): Project2Define?

    fun findByDefineIdAndProjectName(defineId: String, projectName: String): List<Project2Define>?

    fun countByAlias(alias: String): Long

    fun countByProjectNameAndAlias(projectName: String, alias: String): Long

    @Query("select new com.cgs.query.service.AliasDefineNameVersionVO(pd.alias, qd.name,pd.version) from Project2Define pd " +
            ", QueryDefine qd where pd.defineId = qd.id and pd.projectName=?1")
    fun findAliasDefineNameVersionVOByProjectName(projectName: String): List<AliasDefineNameVersionVO>

    fun countByProjectName(projectName: String): Long

    fun findByProjectName(projectName: String): List<Project2Define>?

    fun deleteByProjectName(projectName: String)

    fun deleteByDefineId(defineId: String)
}
